home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / stitchAndExplodeShell.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.5 KB  |  166 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Alias|Wavefront Script File
  18. // MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //    Creation Date : April 27 1999.
  21. //
  22. //<doc>
  23. //<name stitchAndExplodeShell>
  24. //<owner "Alias|Wavefront Unsupported">
  25. //
  26. //<synopsis>
  27. //      string[] stitchAndExplodeShell()
  28. //
  29. //<description>
  30. //        Given a group of NURBS surfaces which are connected, the script
  31. //        stitches the surfaces together as a shell and subsequently 
  32. //        creates trimmed NURBS surface shapes corresponding to the 
  33. //        faces comprising the shell using a surfaceVarGroup.
  34. //<P>
  35. //        The stitchAndExplode is performed  by hooking up
  36. //        the selected NURBS surfaces to a stitchAsNurbsShell node,
  37. //        which in turn is connected to a explodeNurbsShell node.
  38. //<P>
  39. //        This is useful in removing cracks which show up while
  40. //        rendering NURBS surfaces as the tesselation carried out
  41. //        to render the triangles do not have the same vertices 
  42. //        across the shared edges.
  43. //
  44. //<flags>
  45. //      none. 
  46. //
  47. //<returns>
  48. //      string[] : The surface var group. 
  49. //
  50. //<examples>
  51. //        select -r sphere1 fillet1 sphere2 ;
  52. //        string $osrf[] = stitchAndExplodeShell
  53. //      // Result : { varGroup } //
  54. //
  55. //</doc>
  56. //
  57.  
  58. global proc string[] stitchAndExplodeShell()
  59. //
  60. //    Description :
  61. //
  62. {
  63.  
  64.     string $osrf[] ;
  65.     global int $gSelectNurbsSurfacesBit ;
  66.  
  67.     string $slist[] = `ls -sl` ;
  68.     if( size($slist) == 0 ) {
  69.         error "select a  NURBS surface to convert.";
  70.     }
  71.     string $srf[] ;
  72.     $srf = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit $slist` ;
  73.     if( size($srf) == 0 ) {
  74.         error "select at least one NURBS surface.";
  75.         return $osrf ;
  76.     }
  77.  
  78.     // create a stitch node.
  79.     //
  80.     int $i;
  81.     int $ns = size($srf) ;
  82.     string $stitchShell ;
  83.     if( catch( $stitchShell = `createNode stitchAsNurbsShell` ) ) {
  84.         error "Failed in stitchAsNurbsShell node creation !" ;
  85.         return $osrf ;    
  86.     }
  87.  
  88.     string $inAttr ;
  89.     string $outAttr;
  90.     for( $i = 0 ; $i < $ns ; $i++ ) {
  91.         $inAttr = $srf[$i] + ".ws[0]" ;
  92.         $outAttr = $stitchShell + ".is[" + $i + "]" ;
  93.         connectAttr $inAttr $outAttr ;
  94.     }
  95.  
  96.     // create an explode node.
  97.     //
  98.     string $explodeShell ;
  99.     if( catch( $explodeShell = `createNode explodeNurbsShell` ) ) {
  100.         error "Failed in explodeNurbsShell node creation !" ;
  101.         delete $stitchShell ;
  102.         return $osrf ;    
  103.     }
  104.  
  105.     $inAttr = $stitchShell + ".osh" ;
  106.     $outAttr = $explodeShell + ".ish" ;
  107.     connectAttr $inAttr $outAttr ;
  108.  
  109.     // get the stitched pieces.
  110.     //    
  111.     string $varGroup ;
  112.     if( catch( $varGroup = `createNode surfaceVarGroup` ) ) {
  113.         error "Failed in surfaceVarGroup node creation !" ;
  114.         delete $stitchShell ;
  115.         delete $explodeShell ;
  116.         return $osrf ;    
  117.     } 
  118.  
  119.     // connect explode shell output to
  120.     // the vargroup input.
  121.     //
  122.     $inAttr = $explodeShell + ".os" ;
  123.     $outAttr = $varGroup + ".cr" ;
  124.     connectAttr $inAttr $outAttr ;
  125.  
  126.     // create a nurbs surface and temporarily hook
  127.     // it to varGroup for a compute.
  128.     //
  129.     string $tempSrf = `createNode nurbsSurface` ;
  130.     $inAttr = $varGroup + ".l[0]" ;
  131.     $outAttr = $tempSrf + ".cr" ;
  132.     connectAttr $inAttr $outAttr ;
  133.     $outAttr = $tempSrf + ".degreeU" ;
  134.     getAttr $outAttr ;
  135.     
  136.     // get the # of surfaces in var group.
  137.     //
  138.     $outAttr= $varGroup + ".mc" ;
  139.     int $n = `getAttr $outAttr` ;
  140.  
  141.     // delete the temporary surface.
  142.     //
  143.     delete $tempSrf ;
  144.  
  145.     // select the var group.
  146.     //
  147.     if( $n > 0 )  {
  148.         $osrf[0] =  $varGroup;
  149.         select -r $varGroup ;
  150.         string $child[] ;
  151.         $child = `listRelatives $varGroup` ;
  152.     }
  153.  
  154.     // delete history.
  155.     // 
  156.     //delete -ch $varGroup ;
  157.  
  158.     // error message on failure.
  159.     //
  160.     if( $n <= 0 ) {
  161.         error "stitchAndExplodeShell script failed on selected NURBS surfaces.";
  162.     }
  163.  
  164.     return $osrf ;
  165. }
  166.